package jianzhi;

import java.util.Stack;

/**
 * description:
 * author:zt
 * date:2021-10-16
 */
public class jianzhi30 {
    class MinStack {
        private Stack<Integer> stack1, stack2;
        /** initialize your data structure here. */
        public MinStack() {
            stack1 = new Stack<>();
            stack2 = new Stack<>();
        }

        public void push(int x) {
            stack1.push(x);
            if (stack2.isEmpty() || stack2.peek() >= x) stack2.push(x);
        }

        public void pop() {
            if (stack2.peek().equals(stack1.peek())){
                stack2.pop();
            }
            stack1.pop();
        }

        public int top() {
            return stack1.peek();
        }

        public int min() {
            return stack2.peek();
        }
    }
}
